from peewee import *
import json
import os


from orm.RetryOperationalError import RetryMySQLDatabase

with open(os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '/config/mysql.json', 'r',
          encoding='utf8')as fp:
    json_data = json.load(fp)
    # db = pymysql.connect(json_data["url"], json_data["user"], json_data["pwd"], json_data["database"])
database = RetryMySQLDatabase(json_data["database"],
                                 **{'charset': 'utf8', 'use_unicode': True, 'host': json_data["url"],
                            'port': int(json_data["port"]), 'user': json_data["user"],
                            'password': json_data["pwd"]})

# python -m pwiz -e mysql -H 127.0.0.1 -p 3306 -u root -P root -t t_kzz_fx_copy1 lw> kzz.py
class BaseModel(Model):
    class Meta:
        database = database

class TKzzFx(BaseModel):
    cje = CharField(null=True)
    convert_cd_tip = CharField(null=True)
    czjz = CharField(null=True)
    dqsj = CharField(null=True)
    dqsqsy = CharField(null=True)
    force_redeem = CharField(null=True)
    hscfj = CharField(null=True)
    hsl = CharField(null=True)
    hssy = CharField(null=True)
    jgcc = CharField(null=True)
    level = IntegerField(null=True)
    pb = CharField(null=True)
    pj = CharField(null=True)
    qqjz = CharField(null=True)
    qscfj = CharField(null=True)
    sd = CharField(null=True)
    sm = CharField(null=True)
    sygm = CharField(null=True)
    synx = CharField(null=True)
    type = CharField(null=True)
    update_time = CharField(constraints=[SQL("DEFAULT ''")], null=True)
    xj = CharField(null=True)
    yjl = CharField(null=True)
    zdf = CharField(null=True)
    zgj = CharField(null=True)
    zgjg = CharField(null=True)
    zgjz = CharField(null=True)
    zgmc = CharField(null=True)
    zgzd = CharField(null=True)
    zzdm = CharField(null=True)
    zzmc = CharField(null=True)
    zzzb = CharField(null=True)
    dqshsy = CharField(null=True)
    hs_sy  = CharField(null=True)
    class Meta:
        table_name = 't_kzz_fx'
        primary_key = False